# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=containers-common
pkgver=0.60.4
pkgrel=0
pkgdesc="Configuration files for container tools"
url="https://github.com/containers/common"
license="Apache-2.0"
arch="noarch"
options="!check" # no test suite
makedepends="go-md2man"
subpackages="$pkgname-doc"
# Pick the exact versions of common/storage/image vendored in podman.
# Ideally, they should be the same in skopeo and buildah.
# Check them with the list_vendors function.
_common_ver=$pkgver
_storage_ver=1.55.0
_image_ver=5.32.2
_podman_ver=5.2.4
_skopeo_ver=1.16.1
_buildah_ver=1.37.4
_shortnames_ver=2023.02.20
source="https://github.com/containers/common/archive/v$_common_ver/common-$_common_ver.tar.gz
	https://github.com/containers/storage/archive/v$_storage_ver/storage-$_storage_ver.tar.gz
	https://github.com/containers/image/archive/v$_image_ver/image-$_image_ver.tar.gz
	https://github.com/containers/podman/archive/v$_podman_ver/podman-$_podman_ver.tar.gz
	https://github.com/containers/skopeo/archive/v$_skopeo_ver/skopeo-$_skopeo_ver.tar.gz
	https://github.com/containers/buildah/archive/v$_buildah_ver/buildah-$_buildah_ver.tar.gz
	https://github.com/containers/shortnames/archive/v$_shortnames_ver/shortnames-$_shortnames_ver.tar.gz
	"

list_vendors() {
	unpack

	for tool in podman-$_podman_ver skopeo-$_skopeo_ver buildah-$_buildah_ver; do
		cd "$srcdir"/$tool
		msg $tool
		grep github.com/containers/common go.mod
		grep github.com/containers/storage go.mod
		grep github.com/containers/image go.mod
	done
}

prepare() {
	default_prepare

	# fix go-md2man path in containers/storage
	sed -E 's/(GOMD2MAN =).*/\1 go-md2man/' -i "$srcdir"/storage-$_storage_ver/docs/Makefile

	# set default storage driver
	sed -E 's/(driver =) ""/\1 "overlay"/' -i "$srcdir"/storage-$_storage_ver/storage.conf

	# set unqualified-search-registries
	sed -E 's/# (unqualified-search-registries =).*/\1 ["docker.io"]/' -i "$srcdir"/image-$_image_ver/registries.conf
}

build() {
	cd "$srcdir"/common-$_common_ver
	make -C docs

	cd "$srcdir"/storage-$_storage_ver
	make -C docs

	cd "$srcdir"/image-$_image_ver
	make docs
}

package() {
	install -d "$pkgdir"/etc/containers/certs.d
	install -d "$pkgdir"/etc/containers/oci/hooks.d
	install -d "$pkgdir"/var/lib/containers/sigstore

	cd "$srcdir"/common-$_common_ver
	install -Dm644 pkg/config/containers.conf "$pkgdir"/etc/containers/containers.conf
	install -Dm644 pkg/config/containers.conf "$pkgdir"/usr/share/containers/containers.conf
	install -Dm644 pkg/seccomp/seccomp.json "$pkgdir"/etc/containers/seccomp.json
	install -Dm644 pkg/seccomp/seccomp.json "$pkgdir"/usr/share/containers/seccomp.json
	make -C docs install PREFIX=/usr DESTDIR="$pkgdir"

	cd "$srcdir"/storage-$_storage_ver
	install -Dm644 storage.conf "$pkgdir"/etc/containers/storage.conf
	install -Dm644 storage.conf "$pkgdir"/usr/share/containers/storage.conf
	make -C docs install DESTDIR="$pkgdir"

	cd "$srcdir"/image-$_image_ver
	install -Dm644 registries.conf "$pkgdir"/etc/containers/registries.conf
	make install DESTDIR="$pkgdir"

	cd "$srcdir"/skopeo-$_skopeo_ver
	install -Dm644 default-policy.json "$pkgdir"/etc/containers/policy.json
	install -Dm644 default.yaml "$pkgdir"/etc/containers/registries.d/default.yaml

	cd "$srcdir"/shortnames-$_shortnames_ver
	install -Dm644 shortnames.conf "$pkgdir"/etc/containers/registries.conf.d/00-shortnames.conf
}

doc() {
	default_doc
	pkgdesc="Man pages for container tools"
}

sha512sums="
5d61415d4959486223a36ff98304363a558e6da9ccbdca94f976649a37d404ac00c8454019f60a79360029c91c9565d22868b109dbb84c19f13377e0e23dcc4d  common-0.60.4.tar.gz
4c035385167c4c3f6048f8bc2bbbd3cfe9993390d580449e0e5b52576a27d286bd536799c96e46d946b9bfa61ff7263325145acddd7fabfbfbacb967d81843d3  storage-1.55.0.tar.gz
7498f9e446b2c205b033703641f7cfcb6c8bd8f097b12ef3f734c94772d63fc7b9b40a6700d53d93919d2c34772f079aa3cb7d9f9e5a130b6587f4fe2a558df6  image-5.32.2.tar.gz
c6dc05cb377ba6ca3bf7a8d7875c97af9e82b972812702e011e41f7922a4546166061dd5fb809fbef9dd13ee233744de7b7fe16906d8d9631133fc4205a980c5  podman-5.2.4.tar.gz
104b2492901a172e2ba75179492f9e8bf070aec649596ea902384d7a5d875665d8d28e2fc41cf69895208ccfca5e96c2cadeabd235143b0ec5da12e7edc31fcf  skopeo-1.16.1.tar.gz
12f3155054acfcdded3e69b06ced38415cd0a7be125f03dd2de851e0ca056d8a7b71e372ac602ff767f25ccfdce08d8a087c529639fa9172021ad11435dcff20  buildah-1.37.4.tar.gz
856dbbeb2acda276e9605bd1ecec0f8d65952c597ee2af61dd8909d7d3c04e5ef06c40b69ec4a98f79e623c536850f614c1b0af3a19637e300e7d3a285933193  shortnames-2023.02.20.tar.gz
"
